package com.calvin.study.multithread.thread;

//理解Thread线程启动的过程。
public class Thread02 {

	public static void main(String[] args) {
		Tigger t = new Tigger();
		ThreadProxy tp = new ThreadProxy(t);
		tp.start();
	}

}

class Tigger implements Runnable {
	int count = 0;

	@Override
	public void run() {
		while (true) {
			System.out.println("老虎嗷唔，嗷唔叫~" + ++count);

			if (count >= 10) {
				break;
			}
		}
	}

}

class ThreadProxy implements Runnable {

	// 目标类 比如实现Runnable接口
	private Runnable target;

	// 构造方法，为target赋值
	public ThreadProxy(Runnable target) {
		this.target = target;
	}

	// 启动线程
	public void start() {
		start0();
	}

	// 模拟JVM，执行目标类run方法
	private void start0() {
		run();
	}
	
	@Override
	public void run() {
		// 调用目标类的run方法
		if (null != target) {
			target.run();
		}
	}

}
